﻿#include "CDevFollow.h"

CDevFollow::CDevFollowTrush CDevFollow::uTrush;
CDevFollow* CDevFollow::m_pInstance = nullptr;            //单例类
QMutex CDevFollow::m_locker;

CDevFollow::CDevFollow(QObject *parent)
{}

CDevFollow::~CDevFollow()
{}

//获取单例
CDevFollow * CDevFollow::getInstance()
{
	if (nullptr == m_pInstance)
	{
		m_locker.lock();
		if (nullptr == m_pInstance)
		{
			CDevFollow* pInstance = new CDevFollow();
			m_pInstance = pInstance;
		}
		m_locker.unlock();
	}

	return m_pInstance;
}

//添加到关注列表
void CDevFollow::addDevInFllow(SDevFollowParam stParam)
{
	QString sDevGuid = stParam.sDevGuid;
	m_locker.lock();
	m_mapDevFollow.insert(sDevGuid, stParam);
	m_locker.unlock();
}

//移除关注
void CDevFollow::removeDevFollow(QString sDevGuid)
{
	m_locker.lock();
	if (m_mapDevFollow.contains(sDevGuid))
	{
		m_mapDevFollow.remove(sDevGuid);
	}
	m_locker.unlock();
}

//是否存在关注
bool CDevFollow::isExistFollow(QString sDevGuid)
{
	if (m_mapDevFollow.contains(sDevGuid))
	{
		return true;
	}

	return false;
}

//获得设备关注信息
SDevFollowParam CDevFollow::getDevFollowParam(QString sDevGuid)
{
	m_locker.lock();
	SDevFollowParam stDevFollowParam;
	if (m_mapDevFollow.contains(sDevGuid))
	{
		stDevFollowParam = m_mapDevFollow.value(sDevGuid);
	}
	m_locker.unlock();

	return stDevFollowParam;
}
